package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.PermissionDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author liu
 * @version 1.0.0
 * @createTime 2020年10月09日
 * @Description 权限service实现
 */
@Service
@Slf4j
public class PermissionServiceImpl implements PermissionService {
    @Autowired
  private PermissionDao permissionDao;
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
          log.info("[权限分页查询service]data:{}",queryPageBean);
          //使用插件助手
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
       Page<Permission> page=permissionDao.selectByCondition(queryPageBean.getQueryString());

        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Permission permission) {
        log.info("[新增权限service]data:{}",permission);
        permissionDao.insert(permission);

    }

    @Override
    public Permission findById(Integer id) {
        log.info("[权限根据id查询数据service ]id:{}",id);
       Permission permission= permissionDao.selectById(id);

        return permission;
    }

    @Override
    public void edit(Permission permission) {
        log.info("[编辑权限service]permission:{}",permission);
        permissionDao.updata(permission);
    }
    @Transactional
    @Override
    public void delete(Integer id) {
        log.info("[删除权限]id:{}",id);
        //相应的删除关系
        permissionDao.deleteRoleIdByPermissonId(id);
        permissionDao.delete(id);
    }

    @Override
    public List<Permission> findAll() {



        return permissionDao.selectAll();
    }


}
